<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" 
	xmlns:pe="http://primefaces.org/ui/extensions"
	template="/WEB-INF/templates/template.xhtml">
	
<ui:define name="headIncludes">
	<f:event listener="#{servicoBean.initialize}" type="preRenderView"/>
</ui:define>
	
	<ui:define name="pageName">Consultar Serviço</ui:define>
	
	<ui:define name="buttons">
		<p:commandButton value="Novo" style="height:28px;" action="#{servicoBean.changeToNew}" icon="ui-icon-plus"/>
	</ui:define>
	
	<ui:define name="content">	
		<p:panel>
			<div>
				<p:messages globalOnly="false" autoUpdate="true" />
				<h:panelGrid columns="7">
					<h:outputText value="Filtrar por:" />
									
					<p:inputText id="inputSearchFilterCod" style="width:50px;" value="#{servicoBean.filterId}" maxlength="15" title="Código"
						onkeypress="if (event.keyCode == 13) { event.preventDefault();  $('#searchButton').click(); }">
						<pe:keyFilter regEx="/[\d]/" />
					</p:inputText>
					<p:watermark value="Código" for="inputSearchFilterCod"/>
					
					<p:inputText id="inputSearchFilter" style="width:300px;" value="#{servicoBean.filter}" maxlength="50" title="Descrição"
						onkeypress="if (event.keyCode == 13) { event.preventDefault();  $('#searchButton').click(); }"/>
					<p:watermark value="Descrição" for="inputSearchFilter"/>
					
					<p:commandButton value="Consultar" style="height:28px;" id="searchButton" actionListener="#{servicoBean.fillByFilter}" icon="ui-icon-search"/>					
				</h:panelGrid>
				
				<div style="padding-top:10px;">
					<p:dataTable var="servico"
						id="tableServico" value="#{servicoBean.servicos}"
						paginator="true" rows="10" paginatorPosition="bottom"
						emptyMessage="Não há registros"
						selection="#{servicoBean.currentServico}" selectionMode="single" rowKey="#{servico.id}">  
						
						<p:ajax event="rowSelect" listener="#{servicoBean.changeToDetail}"/>
						
				        <p:column headerText="Código" style="width:100px;">  
				            <h:outputText value="#{servico.id}" />  
				        </p:column>  
				  
				        <p:column headerText="Descrição">  
				            <h:outputText value="#{servico.descricao}" />  
				        </p:column>	
				        
				        <p:column headerText="" width="50">
							<p:commandButton icon="ui-icon-pencil"
								style="width: 24px; height: 24px;" action="#{servicoBean.changeToEdit(servico.id)}" title="Editar"/>
							<p:spacer width="10px" />
							<p:commandButton icon="ui-icon-trash"
								style="width: 24px; height: 24px;" actionListener="#{servicoBean.changeToDelete(servico.id)}" title="Excluir"/>
						</p:column>	
			  		</p:dataTable>
				</div>
			</div>
		</p:panel>						 
	</ui:define>
	<ui:define name="popups">

	<p:dialog appendToBody="true" modal="true" closable="false" widgetVar="popupConfirmDelete"
		width="300" resizable="false" header="Confirmação de exclusão" height="90">
		<h:form>
			<div style="margin-top: 10px;">
				<h:outputText value="Confirma a exclusão do registro?"/>
			</div>
			<div align="right" style="margin-top: 15px; margin-bottom: 15px;">
				<p:commandButton value="Excluir" actionListener="#{servicoBean.remove}" oncomplete="popupConfirmDelete.hide()" icon="ui-icon-trash"/>
				<p:commandButton value="Cancelar" onclick="popupConfirmDelete.hide()" icon="ui-icon-cancel"/>
			</div>		
		</h:form>			
		</p:dialog>	
		
	</ui:define>
</ui:composition>